/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package View.Administrator;


import Entities.Actor;
import Entities.Movie;
import Services.ActorService;
import java.util.Date;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import javax.persistence.TypedQuery;
import javax.swing.ListModel;
import Controllers.MovieController;
import View.User.MovieView;
/**
 *
 * @author sebastian
 */
public class AdminView extends javax.swing.JFrame {
    MovieController mC = new MovieController(); 
    RemoveConfirmation remove = new RemoveConfirmation(); //The remove confirmation win
    AddMovie addmov = new AddMovie();
    /**
     * Creates new form AdminView
     */
    public AdminView() {
        initComponents();
        //Init the list of current movies
                      
        jListCurrentMovies.setListData(mC.getAllMoviesNames());
        jListCurrentMovies.setSelectedIndex(0);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jButtonAddMovie = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jButtonRemoveMovies = new javax.swing.JButton();
        jButtonEditMovie = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        jPanelResults = new javax.swing.JPanel();
        jButtonFinishAdmin = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        jListCurrentMovies = new javax.swing.JList();
        jLabel3 = new javax.swing.JLabel();

        jButtonAddMovie.setFont(new java.awt.Font("Ubuntu", 1, 15)); // NOI18N
        jButtonAddMovie.setForeground(new java.awt.Color(26, 188, 2));
        jButtonAddMovie.setText("ADD MOVIE");
        jButtonAddMovie.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButtonAddMovieMouseClicked(evt);
            }
        });
        jButtonAddMovie.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonAddMovieActionPerformed(evt);
            }
        });

        jLabel1.setText("MANAGMENT OF MOVIES STORED IN THE DATA BASE");

        jButtonRemoveMovies.setFont(new java.awt.Font("Ubuntu", 1, 15)); // NOI18N
        jButtonRemoveMovies.setForeground(new java.awt.Color(255, 0, 0));
        jButtonRemoveMovies.setText("REMOVE MOVIE");
        jButtonRemoveMovies.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonRemoveMoviesActionPerformed(evt);
            }
        });

        jButtonEditMovie.setFont(new java.awt.Font("Ubuntu", 1, 15)); // NOI18N
        jButtonEditMovie.setForeground(new java.awt.Color(0, 175, 206));
        jButtonEditMovie.setText("EDIT MOVIE");
        jButtonEditMovie.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButtonEditMovieMouseClicked(evt);
            }
        });

        jLabel2.setText("What do you like to do?");

        jButtonFinishAdmin.setForeground(new java.awt.Color(1, 1, 1));
        jButtonFinishAdmin.setText("FINISH");
        jButtonFinishAdmin.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonFinishAdminActionPerformed(evt);
            }
        });

        jListCurrentMovies.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "Item 1", " " };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        jScrollPane2.setViewportView(jListCurrentMovies);

        jLabel3.setText("Current movies in our Data Base:");

        javax.swing.GroupLayout jPanelResultsLayout = new javax.swing.GroupLayout(jPanelResults);
        jPanelResults.setLayout(jPanelResultsLayout);
        jPanelResultsLayout.setHorizontalGroup(
            jPanelResultsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelResultsLayout.createSequentialGroup()
                .addGap(59, 59, 59)
                .addGroup(jPanelResultsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel3)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 360, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanelResultsLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jButtonFinishAdmin)
                .addContainerGap())
        );
        jPanelResultsLayout.setVerticalGroup(
            jPanelResultsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanelResultsLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jLabel3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jButtonFinishAdmin))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(25, 25, 25)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel2)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(29, 29, 29)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jButtonAddMovie)
                                    .addComponent(jButtonEditMovie)))))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(41, 41, 41)
                        .addComponent(jButtonRemoveMovies)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 22, Short.MAX_VALUE)
                .addComponent(jPanelResults, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
            .addGroup(layout.createSequentialGroup()
                .addGap(135, 135, 135)
                .addComponent(jLabel1)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jButtonAddMovie, javax.swing.GroupLayout.PREFERRED_SIZE, 52, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(24, 24, 24)
                        .addComponent(jButtonEditMovie, javax.swing.GroupLayout.PREFERRED_SIZE, 57, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(29, 29, 29)
                        .addComponent(jButtonRemoveMovies, javax.swing.GroupLayout.PREFERRED_SIZE, 53, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(72, 72, 72))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jPanelResults, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap(24, Short.MAX_VALUE))))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButtonFinishAdminActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonFinishAdminActionPerformed
        this.setVisible(false);
    }//GEN-LAST:event_jButtonFinishAdminActionPerformed

    private void jButtonRemoveMoviesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonRemoveMoviesActionPerformed
        
        Integer indexM = jListCurrentMovies.getSelectedIndex();
        String nametoremove = jListCurrentMovies.getSelectedValue().toString();       
        
        remove.RemoveConfirmationName(nametoremove, jListCurrentMovies);
        
                
        remove.setLocationRelativeTo(this);
        remove.setVisible(true);                
    }//GEN-LAST:event_jButtonRemoveMoviesActionPerformed

    private void jButtonAddMovieActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonAddMovieActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jButtonAddMovieActionPerformed

    private void jButtonAddMovieMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButtonAddMovieMouseClicked
        addmov.addMovie(jListCurrentMovies);
        addmov.setLocationRelativeTo(this);
        addmov.setVisible(true);
    }//GEN-LAST:event_jButtonAddMovieMouseClicked

    private void jButtonEditMovieMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButtonEditMovieMouseClicked
        String nameTheMovie = (String)jListCurrentMovies.getSelectedValue();
        System.out.println("item"+nameTheMovie);    
        Movie movie = new Movie();
        mC.getMoviesbyName(nameTheMovie);
        movie = mC.getSingleMovie(nameTheMovie);
        UpdateMovie upMov = new UpdateMovie();
        upMov.updateMovie(movie);
        upMov.setLocationRelativeTo(this);
        upMov.setVisible(true);
               
        
        
    }//GEN-LAST:event_jButtonEditMovieMouseClicked

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(AdminView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(AdminView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(AdminView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(AdminView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new AdminView().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonAddMovie;
    private javax.swing.JButton jButtonEditMovie;
    private javax.swing.JButton jButtonFinishAdmin;
    private javax.swing.JButton jButtonRemoveMovies;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JList jListCurrentMovies;
    private javax.swing.JPanel jPanelResults;
    private javax.swing.JScrollPane jScrollPane2;
    // End of variables declaration//GEN-END:variables
}
